package com.common.zrd.bean;

/**
 * @author: zrd
 * @Date: 2019/12/6 11:29
 * @Description:
 */

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class CollectionCopyUtil {

    public static <T> List copyList(List<T> list, Class tClass) {
        if (isEmpty(list)) {
            return new ArrayList();
        }
        return JSON.parseArray(JSON.toJSONString(list), tClass);
    }

    public static boolean isEmpty(Collection coll) {
        return (coll == null || coll.isEmpty());
    }
    public static <T> List copyListBean(List<T> list, Class tClass) {
        if (isEmpty(list)) {
            return new ArrayList();
        }
        return JSON.parseArray(JSON.toJSONString(list), tClass);
    }

    public static Map<String, Object> copyMap(Map map) {
        return JSON.parseObject(JSON.toJSONString(map));
    }
}
